<?php
/**
 * User: Titan
 * Date: Sep 29, 2010
 * Time: 11:23:05 PM
 */

/**
 * uninstall_settings()
 * 
 * deletes the settings.inc file that stores database information
 * 
 * @return
 */
function uninstall_settings()
{
	if (file_exists('./settings.inc'))
	{
		unlink('./settings.inc');
	}
}

/**
 * uninstall_schema()
 * 
 * uninstalls the BugZapp database
 * 
 * @return
 */
function uninstall_schema()
{
	global $db_url;
	
	if (isset($db_url))
	{
		$url = parse_url($db_url);
		$db_schema = substr(urldecode($url['path']), 1);
		
		$result = db_query("DROP DATABASE IF EXISTS %s", $db_schema);
		if ($result !== FALSE)
		{			
			system_set_message('The <code>' . $db_schema . '</code> database was successfully removed.');
		}
		else
		{
			system_set_message('The <code>' . $db_schema . '</code> database was not removed.');
		}
	}
}


/**
 * uninstall_system()
 * 
 * uninstalls the entire BugZapp database including all tables
 * 
 * @return
 */
function uninstall_system()
{
	Task::uninstall();
	Developer::uninstall();
	Milestone::uninstall();
	Feature::uninstall();
	
	uninstall_schema();
	
	uninstall_settings();
}
